home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / aplictns / ifs_1_4 / part03 < prev   
Text File  |  1990-03-06  |  26KB  |  776 lines

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i102: IFS 1.4 - an iterated function system viewer, Part03/03
  5. Message-ID: <11656@xanth.cs.odu.edu>
  6. Date: 6 Mar 90 22:41:29 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: fullmer@alfalfa.sps.mot.com (Glen Fullmer)
  9. Lines: 762
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: fullmer@alfalfa.sps.mot.com (Glen Fullmer)
  15. Posting-number: Volume 90, Issue 102
  16. Archive-name: applications/ifs-1.4/part03
  17.  
  18. #!/bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 3 (of 3)."
  25. # Contents:  source/ifsout.c
  26. # Wrapped by tadguy@xanth on Tue Mar  6 17:38:08 1990
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'source/ifsout.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'source/ifsout.c'\"
  30. else
  31. echo shar: Extracting \"'source/ifsout.c'\" \(23178 characters\)
  32. sed "s/^X//" >'source/ifsout.c' <<'END_OF_FILE'
  33. X/*
  34. X*
  35. X*     IFSout.c - Iterated Function System
  36. X*                uses IFS to create a IFS-Construction Image
  37. X*     Released to the Public Domain - 1989 The Software Glen Company
  38. X*    
  39. X*
  40. X*/
  41. X
  42. X#include "standard.h"
  43. X#include "ifs.h"
  44. X#include "ifsout.h"
  45. X#include "safeclose.h"
  46. X
  47. Xlong   timeint;
  48. Xshort  gadcount;
  49. Xfloat  x=0., y=0.;            /* the (real) x y before translation*/
  50. XUWORD  colortab[32]; 
  51. Xint    currentfun = 0;
  52. Xint    numoffun = 1;          /* startout with two functions=numfun+1 */
  53. Xchar   fname[MAXFNLEN];
  54. Xchar   fn[MAXFNLEN/2];
  55. Xchar   fdir[MAXFNLEN/2] = ":ifs/coors";
  56. Xshort   vectorsw = FALSE, 
  57. X        displaynumsw = TRUE, 
  58. X        pausesw = FALSE,
  59. X        blackbacksw = TRUE,
  60. X        adjopen = FALSE;
  61. X
  62. XUSHORT mx, my;                /* mouse location */
  63. X
  64. X/*****************
  65. X** Main Program **
  66. X*****************/
  67. X
  68. Xint main()
  69. X{
  70. X  ULONG  class;
  71. X  UWORD  tempcolor;
  72. X  USHORT MenuNum, ItemNum, code;
  73. X  struct MenuItem *Item;   
  74. X  APTR   aAddress;
  75. X       
  76. X  short  corner=0, adjdown = FALSE, boxmoved = FALSE;
  77. X  
  78. X  void   graphit();
  79. X  void   gadgetmessage();
  80. X  void   initialit();
  81. X  void   clearscreen();
  82. X  void   setcolor();
  83. X  void   setupgad();
  84. X  void   closeout();
  85. X  void   drawvectors();
  86. X  void   autoadj();
  87. X  int    closeby();
  88. X  void   adjust();
  89. X  void   displaynums();
  90. X  void   getifsfun();
  91. X  void   checkswitches();
  92. X
  93. X  void   putifsfun();
  94. X
  95. X/* default to small flower */
  96. X  float funs[FUNLIMIT][6] = { {0.20, 1.00, -0.65, 0.82, 1.11, 0.00},
  97. X                              {0.40, 0.00, 0.30, -0.32, 0.32, 0.00}},
  98. X        percent[FUNLIMIT] = { 0.66, 1.00}, 
  99. X        xyscale = 0.11;                       /* could be .25;     */ 
  100. X
  101. X  int   xoff = WIDTH/2 - 24, 
  102. X        yoff = HEIGHT/2 + 28,
  103. X        i, j;
  104. X
  105. X  initialit(funs,percent,&xyscale,&xoff,&yoff,¤tfun);
  106. X   
  107. X  FOREVER {
  108. X  
  109. X   if (pausesw) Wait((1 << w->UserPort->mp_SigBit) | 
  110. X             (1 << adjwin->UserPort->mp_SigBit));
  111. X    if ((message = (struct IntuiMessage *)GetMsg(w->UserPort))) {
  112. X      class = message->Class;
  113. X      code  = message->Code;
  114. X      mx    = message->MouseX;
  115. X      my    = message->MouseY;
  116. X
  117. X      aAddress = message->IAddress;
  118. X         
  119. X      ReplyMsg(message);       /* Can't reply until done using it!   */
  120. X      switch (class) {
  121. X        case  CLOSEWINDOW:   /* Exit the program */
  122. X          if (adjopen) 
  123. X            CloseWindowSafely(adjwin);
  124. X          closeout();
  125. X          exit(0);
  126. X          break;
  127. X        case MOUSEBUTTONS:
  128. X          if (code == SELECTDOWN) {
  129. X            if (vectorsw) {
  130. X              if (corner=closeby (funs, ¤tfun, numoffun, mx, my) )
  131. X                adjdown = TRUE;
  132. X              else 
  133. X                if (numoffun > 0) currentfun = (currentfun + 1) % 
  134. X                                               (numoffun   + 1);
  135. X            }
  136. X            else setcolor();
  137. X          }
  138. X          else 
  139. X            if (code == SELECTUP) {
  140. X              adjdown = FALSE;
  141. X          if (boxmoved) {
  142. X                clearscreen();
  143. X                boxmoved = FALSE;
  144. X                for (j=0;j<10;j++)           /* settle in on function */
  145. X                    graphit(funs,percent, xyscale, xoff, yoff, FALSE); 
  146. X                }
  147. X              checkswitches(rp,funs,percent,currentfun,
  148. X                           numoffun,vectorsw,displaynumsw);
  149. X        }
  150. X          setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  151. X                    xoff, yoff, currentfun, numoffun, stxt, adjopen);
  152. X          break;               
  153. X        case INTUITICKS:
  154. X          if (adjdown) {
  155. X            boxmoved = TRUE;
  156. X            adjust(corner, rp, funs, currentfun, mx, my);
  157. X          }
  158. X          break;
  159. X        case MENUPICK:
  160. X          while (code != MENUNULL) {
  161. X            Item = (struct MenuItem *) ItemAddress(&Menu[0], code);
  162. X            MenuNum = MENUNUM( code ); 
  163. X            ItemNum = ITEMNUM( code );
  164. X            switch( MenuNum) {
  165. X              case 0:                  /* Project Menu  */
  166. X                switch( ItemNum ) {
  167. X                  case 0:              /* About Menu    */
  168. X                    AutoRequest(w, &ReqText1, NULL,
  169. X                      &OKIText, 10, 20, 310, 180);
  170. X                    break;
  171. X                  case 1:              /* Save Current  */
  172. X                    if (get_fname(w,screen,"Save File",fn,fdir) 
  173. X                      != NULL) {
  174. X                      fname[0] = '\0';
  175. X                      strcat(fname,fdir);
  176. X
  177. X/* need to check if we need a / or not */
  178. X                      if (fdir[strlen(fdir) - 1] != ':')
  179. X                        strcat(fname,"/");
  180. X
  181. X                      strcat(fname,fn);
  182. X                      putifsfun(fname,numoffun,funs,percent,
  183. X                                colortab,xoff,yoff,xyscale);
  184. X                      }
  185. X                    checkswitches(rp,funs,percent,currentfun,
  186. X                                  numoffun,vectorsw,displaynumsw);
  187. X                    break;
  188. X                  case 2:              /* Get IFS       */
  189. X                    if (get_fname(w,screen,"Get File",fn,fdir) != NULL) {
  190. X                      fname[0] = '\0';
  191. X                      strcat(fname,fdir);
  192. X
  193. X/* need to check if we need a / or not */
  194. X                      if (fdir[strlen(fdir) - 1] != ':')
  195. X                        strcat(fname,"/");
  196. X                      strcat(fname,fn);
  197. X                      getifsfun(fname,&numoffun,funs, percent,
  198. X                                colortab,&xoff,&yoff,&xyscale);
  199. X                              
  200. X                      currentfun = 0;
  201. X                      PInfos[0].HorizBody = FFFF/(numoffun+1);
  202. X                      setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  203. X                              xoff, yoff, currentfun, numoffun, stxt, adjopen);
  204. X                      for (j=0;j<10;j++)           /* settle in on function */
  205. X                        graphit(funs, percent, xyscale, xoff, yoff, FALSE); 
  206. X                      clearscreen();
  207. X                      checkswitches(rp,funs,percent,currentfun,
  208. X                                    numoffun,vectorsw,displaynumsw);
  209. X                    }
  210. X                    break;                
  211. X                  case 3:              /* To WB         */
  212. X                    ScreenToBack(screen);
  213. X                    break;
  214. X                  case 4:              /* quit          */
  215. X                    if (adjopen) 
  216. X                      CloseWindowSafely(adjwin);
  217. X                    closeout();
  218. X                    exit(0);
  219. X                    break;
  220. X                }
  221. X                break;
  222. X              case 1:                  /* Function Menu */
  223. X                switch( ItemNum ) {
  224. X                  case 0:              /* Zoom to Fit   */
  225. X                    x=0.; y=0.;            
  226. X                    autoadj(funs, percent, &xyscale, &xoff, &yoff, ¤tfun);
  227. X                    clearscreen();
  228. X                    checkswitches(rp,funs,percent,currentfun,
  229. X                                  numoffun,vectorsw,displaynumsw);
  230. X                    break;
  231. X                  case 1:              /* Zoom out x 2   */
  232. X                    xyscale = xyscale / 2;
  233. X                    clearscreen();
  234. X                    checkswitches(rp,funs,percent,currentfun,
  235. X                                  numoffun,vectorsw,displaynumsw);
  236. X                    setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  237. X                            xoff, yoff, currentfun, numoffun, stxt, adjopen);
  238. X                    break;
  239. X                  case 2:         /* Open adjust window in our new screen */
  240. X                    if (!adjopen) {
  241. X                      nadjwin.Screen = screen; 
  242. X                      adjwin = (struct Window *)OpenWindow(&nadjwin);
  243. X                      if (adjwin == NULL) {
  244. X                        closeout();
  245. X                        exit(6);
  246. X                      }
  247. X                      adjopen = TRUE;
  248. X                      setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  249. X                              xoff, yoff,currentfun, numoffun, stxt, adjopen);
  250. X                    }
  251. X                    else {
  252. X                      WindowToFront(adjwin);
  253. X                    }
  254. X                    break;
  255. X                  case 3:              /* Another Function */
  256. X                    if (numoffun < FUNLIMIT-1) {
  257. X                      numoffun++;
  258. X                      currentfun = numoffun;   
  259. X                      /* reset the new function */
  260. X                      if(displaynumsw) 
  261. X                        clearscreen();
  262. X                      funs[currentfun][0] = 1.;
  263. X                      funs[currentfun][1] = 0.;
  264. X                      funs[currentfun][2] = 0.;
  265. X                      funs[currentfun][3] = 1.;
  266. X                      funs[currentfun][4] = 0.;
  267. X                      funs[currentfun][5] = 0.;
  268. X                      adjpercent(numoffun, percent);
  269. X                      setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  270. X                              xoff, yoff,  currentfun, numoffun, stxt, adjopen);
  271. X                      checkswitches(rp,funs,percent,currentfun,
  272. X                                    numoffun,vectorsw,displaynumsw);
  273. X                    }
  274. X                    break; 
  275. X                  case 4:               /* Erase Current */
  276. X                    if(numoffun > 1) {
  277. X                      for (i=currentfun;i<numoffun;i++) 
  278. X                        for (j=0;j<6;j++) 
  279. X                         funs[i][j] = funs[i+1][j];
  280. X                      funs[numoffun][0] = 1.;
  281. X                      funs[numoffun][1] = 0.;
  282. X                      funs[numoffun][2] = 0.;
  283. X                      funs[numoffun][3] = 1.;
  284. X                      funs[numoffun][4] = 0.;
  285. X                      funs[numoffun][5] = 0.;
  286. X                      percent[numoffun] = 0.;
  287. X                      if (currentfun == numoffun) currentfun--;
  288. X                      numoffun--;
  289. X                      setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  290. X                              xoff, yoff,  currentfun, numoffun, stxt, adjopen);
  291. X                      clearscreen();
  292. X                      checkswitches(rp,funs,percent,currentfun,
  293. X                                    numoffun,vectorsw,displaynumsw);
  294. X                    }
  295. X                    break;
  296. X                  case 5:               /* Erase All     */     
  297. X                    numoffun = 1;       /* Leave two     */
  298. X                    currentfun = 0;
  299. X                    for (i=0;i<FUNLIMIT;i++)  {
  300. X                      funs[i][0] = 1.;
  301. X                      funs[i][1] = 0.;
  302. X                      funs[i][2] = 0.;
  303. X                      funs[i][3] = 1.;
  304. X                      funs[i][4] = 0.;
  305. X                      funs[i][5] = 0.;
  306. X                      percent[i] = 0.;
  307. X                    }
  308. X                    percent[0]=0.5;           /* for the two left */
  309. X                    percent[1]=1.;
  310. X                    setpots(adjwin, gads, PInfos, funs, percent, xyscale, 
  311. X                            xoff, yoff,  currentfun, numoffun, stxt, adjopen);
  312. X                    clearscreen();
  313. X                    checkswitches(rp,funs,percent,currentfun,
  314. X                                  numoffun,vectorsw,displaynumsw);
  315. X                    break;
  316. X                }   /* end of inner switch */
  317. X
  318. X              break;
  319. X            case 2:            /*  Switches     */
  320. X              switch( ItemNum ) {
  321. X                case 0:         /*  Toggle Boxes */
  322. X                  if (vectorsw) {
  323. X                    vectorsw = FALSE;
  324. X                    clearscreen();
  325. X                  }
  326. X                  else {
  327. X                    vectorsw = TRUE;
  328. X                  }
  329. X                  checkswitches(rp,funs,percent,currentfun,
  330. X                                numoffun,vectorsw,displaynumsw);
  331. X                  break;
  332. X
  333. X                case 1:        /* Toggle Numbers */
  334. X                  if (displaynumsw) {
  335. X                    displaynumsw = FALSE;
  336. X                    clearscreen();
  337. X                    if (vectorsw) 
  338. X                      drawvectors(rp, funs, numoffun, currentfun);
  339. X                  }
  340. X                  else {
  341. X                    displaynumsw = TRUE;
  342. X                    displaynums(rp, funs, percent, currentfun, numoffun);
  343. X                  }
  344. X                  break;
  345. X        
  346. X                case 2:               /* Pause*/
  347. X                  if (pausesw) {
  348. X                    pausesw = FALSE;
  349. X                    ModifyIDCMP(w,CLOSEWINDOW|MOUSEBUTTONS|MENUPICK|INTUITICKS);
  350. X                    if(adjopen)
  351. X                      ModifyIDCMP(adjwin,CLOSEWINDOW|GADGETUP);
  352. X                  }
  353. X                  else {
  354. X                    pausesw = TRUE;   /* set to only look at menupicks/close */
  355. X                    ModifyIDCMP(w,CLOSEWINDOW|MENUPICK);
  356. X                    if(adjopen)
  357. X                      ModifyIDCMP(adjwin,CLOSEWINDOW);
  358. X                  }
  359. X                  break;
  360. X                case 3:               /* Toggle Bk/Fg  */
  361. X                  if (blackbacksw) {
  362. X                    blackbacksw = FALSE;
  363. X                  }
  364. X                  else {
  365. X                    blackbacksw = TRUE;
  366. X                  }
  367. X                  tempcolor   = colortab[0];
  368. X                  colortab[0] = colortab[1];
  369. X                  colortab[1] = tempcolor;
  370. X                  LoadRGB4(ViewPortAddress(w), colortab, 16);
  371. X                  break;
  372. X              } /* end of inner switch */
  373. X            }   /* end of outer switch */
  374. X          code = Item->NextSelect;
  375. X          }   /* end of if */
  376. X          break;  
  377. X      } /*  end of outer outer switch */
  378. X    } /* end of while */
  379. X
  380. X/*  lets see if you want me to do something to adjwin        */
  381. X
  382. X  if (adjopen) 
  383. X    if((message=(struct IntuiMessage *)GetMsg(adjwin->UserPort))) {
  384. X      class = message->Class;
  385. X      code  = message->Code;
  386. X      aAddress = message->IAddress;
  387. X      ReplyMsg(message);      
  388. X      switch (class) {
  389. X        case  CLOSEWINDOW:        /*  Get rid of the requester     */
  390. X          if (adjopen){
  391. X            CloseWindow(adjwin);
  392. X            adjopen = FALSE;
  393. X          }
  394. X          break;
  395. X        case GADGETUP:       /*reply, then process */
  396. X          gadgetmessage(aAddress,adjwin,funs,percent,&xyscale,&xoff,&yoff,
  397. X                        gads,PInfos,&numoffun,¤tfun,stxt,
  398. X                        displaynumsw,adjopen);
  399. X          for (j=0;j<10;j++)           /* settle in on function         */
  400. X            graphit(funs, percent, xyscale, xoff, yoff, FALSE); 
  401. X          checkswitches(rp,funs,percent,currentfun,
  402. X                        numoffun,vectorsw,displaynumsw);
  403. X          break;            
  404. X      } /* end switch */
  405. X    }  /* end if */
  406. X  if(!adjdown) 
  407. X    graphit(funs, percent, xyscale, xoff, yoff, TRUE); 
  408. X  }   /* end FOREVER */   
  409. X  return(0);
  410. X} /* end main */
  411. X
  412. Xvoid clearscreen() {
  413. X
  414. X   SetAPen(rp,0);
  415. X   RectFill(rp, XSTART, YSTART-HEIGHT, WIDTH-XSTART, YSTART);
  416. X}
  417. X
  418. Xvoid graphit(funs,percent,xyscale,xoff,yoff,drawit)
  419. X
  420. Xfloat funs[][6],percent[],xyscale;
  421. Xint   xoff,yoff,drawit;
  422. X
  423. X{
  424. X  double pk;
  425. X  int i, ix, iy, p;
  426. X  static int color;
  427. X  float newx, newy;
  428. X
  429. X  p = rand();
  430. X               
  431. X  pk = p/(float) INT_MAX;
  432. X
  433. X  i=0;
  434. X
  435. X  while(i<numoffun && pk > percent[i]) {
  436. X        i++;
  437. X     }
  438. X
  439. X  newx = funs[i][0] * x + funs[i][1] * y + funs[i][4];
  440. X  newy = funs[i][2] * x + funs[i][3] * y + funs[i][5];
  441. X
  442. X  x = newx;
  443. X  y = newy;
  444. X
  445. X  ix = x*HEIGHT*xyscale+xoff;            /* Assumes that H<W      */
  446. X  iy = y*HEIGHT*xyscale+yoff;
  447. X
  448. X  if ((color = (i+2)%MAXCOLORS) < 2) 
  449. X    color = color+2;
  450. X  if (drawit && ix>0 && ix<WIDTH && iy>0 && iy<HEIGHT) {
  451. X    SetAPen(rp, color);
  452. X    WritePixel(rp, ix, HEIGHT-iy);
  453. X  }
  454. X}
  455. X
  456. Xvoid initialit (funs,percent,xyscale,xoff,yoff,currentfun)
  457. X
  458. Xfloat funs[][6],percent[],*xyscale;
  459. Xint   *xoff,*yoff,*currentfun;
  460. X
  461. X{
  462. X   int i;
  463. X
  464. X   srand(time(&timeint));        /* Set Random Generator Seed    */
  465. X                                        /* From Time                    */
  466. X   colortab[0] = 0;
  467. X   colortab[1] = 4095;
  468. X
  469. X   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  470. X   if (GfxBase == NULL)
  471. X      exit(2);
  472. X
  473. X   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
  474. X   if (IntuitionBase == NULL) {
  475. X      CloseLibrary(GfxBase);
  476. X      exit(3);
  477. X   }
  478. X
  479. X
  480. X   screen = (struct Screen *)OpenScreen(&ns); 
  481. X   if (screen == NULL) {
  482. X      CloseLibrary(IntuitionBase);
  483. X      CloseLibrary(GfxBase);
  484. X      exit(4);
  485. X      }
  486. X
  487. X   nw.Screen = screen;                /* Open window in our new screen */
  488. X   w = (struct Window *)OpenWindow(&nw);
  489. X   if (w == NULL) {
  490. X      CloseScreen(screen);
  491. X      CloseLibrary(IntuitionBase);
  492. X      CloseLibrary(GfxBase);
  493. X      exit(5);
  494. X      }
  495. X    
  496. X   setupgad();
  497. X  
  498. X   for (i=2;i<FUNLIMIT;i++)  {
  499. X      funs[i][0] = 1.;
  500. X      funs[i][1] = 0.;
  501. X      funs[i][2] = 0.;
  502. X      funs[i][3] = 1.;
  503. X      funs[i][4] = 0.;
  504. X      funs[i][5] = 0.;
  505. X      percent[i] = 0.5;
  506. X      }
  507. X
  508. X   setpots(adjwin, gads, PInfos, funs, percent, *xyscale, *xoff, *yoff,
  509. X           *currentfun, numoffun, stxt, adjopen);
  510. X
  511. X   SetMenuStrip(w, &Menu[0]);
  512. X   ShowTitle(screen, FALSE);           /* No Bars in Arizona           */
  513. X
  514. X   vp = &screen->ViewPort;             /* Set colors in screen's VP    */
  515. X   rp = w->RPort;                      /* Render into the window's RP  */
  516. X   clearscreen();
  517. X
  518. X/* check and write indicators */ 
  519. X   checkswitches(rp,funs,percent,currentfun,numoffun,vectorsw,displaynumsw);
  520. X
  521. X/*  Set the color registers */
  522. X   setcolor();
  523. X
  524. X/* default color for small flower */
  525. X   colortab[2] = 1404;
  526. X   colortab[3] = 3913;
  527. X   LoadRGB4(ViewPortAddress(w), colortab, 16);
  528. X} /* end initialit */
  529. X
  530. Xvoid setcolor()  {
  531. X
  532. X   int i, colorinc;
  533. X
  534. X   colorinc = rand() % 4096;
  535. X   
  536. X   colortab[2] = rand() % 4096;
  537. X
  538. X
  539. X   for (i=3; i<32; i++) 
  540. X      colortab[i] = (colortab[i-1] + colorinc) % 4096;
  541. X
  542. X   LoadRGB4(ViewPortAddress(w), colortab, 16);
  543. X
  544. X   SetBPen(rp, 0);                    /* Insure clean text              */
  545. X
  546. X}
  547. X
  548. Xvoid setupgad() {
  549. X
  550. X  /* This is where the proportional gadgets are set up, using
  551. X   * the templates that were declared staticly.
  552. X  */
  553. X  short i, 
  554. X        gadcount;                     /* index to next available Gadget */
  555. X
  556. X  for(gadcount = 0; gadcount < NUMPROPS-2; gadcount++) {
  557. X    gads[gadcount] = TPropGadget;
  558. X    PInfos[gadcount] = TPropInfo;
  559. X    gads[gadcount].GadgetText = NULL;       /* no text on prop gads */
  560. X    gads[gadcount].GadgetRender = (APTR)
  561. X    &PImages[gadcount];
  562. X    gads[gadcount].SpecialInfo = (APTR)&PInfos[gadcount];
  563. X    gads[gadcount].TopEdge = GADSIZE * (gadcount+2);
  564. X    if(gadcount != 0)
  565. X    gads[gadcount].NextGadget = &gads[gadcount-1];
  566. X  }   /* end for */
  567. X
  568. X  gads[NUMPROPS-2] = ZoomGadget;
  569. X  PInfos[NUMPROPS-2] = TPropInfo;
  570. X  PInfos[NUMPROPS-2].Flags = AUTOKNOB | FREEVERT;
  571. X  gads[NUMPROPS-2].SpecialInfo = (APTR)&PInfos[NUMPROPS-2];
  572. X  gads[NUMPROPS-2].GadgetRender = (APTR) &PImages[NUMPROPS-2];
  573. X  gads[NUMPROPS-2].NextGadget = &gads[NUMPROPS-3];
  574. X
  575. X  gads[NUMPROPS-1] = CenterGadget;
  576. X  PInfos[NUMPROPS-1] = TPropInfo;
  577. X  PInfos[NUMPROPS-1].Flags = AUTOKNOB | FREEVERT | FREEHORIZ;
  578. X  gads[NUMPROPS-1].SpecialInfo = (APTR)&PInfos[NUMPROPS-1];
  579. X  gads[NUMPROPS-1].GadgetRender = (APTR) &PImages[NUMPROPS-1];
  580. X  gads[NUMPROPS-1].NextGadget = &gads[NUMPROPS-2];
  581. X  
  582. X  PInfos[0].HorizBody = FFFF/(numoffun+1);
  583. X
  584. X  /* This is where the String gadgets are set up, using
  585. X     the templates that were declared staticly.
  586. X  */
  587. X
  588. X  for(i=0; i<NUMSTRS; i++) {
  589. X    SInfo[i].Buffer     = &stxt[i][0];
  590. X    SInfo[i].UndoBuffer = NULL;
  591. X    SInfo[i].BufferPos  = 0;
  592. X    SInfo[i].MaxChars   = GSTRLEN;
  593. X    SInfo[i].DispPos    = 0;
  594. X    }
  595. X
  596. X  for(gadcount = NUMPROPS; gadcount < NUMGADS; gadcount++) {
  597. X    gads[gadcount] = TStrngGadget;
  598. X    gads[gadcount].GadgetText = 
  599. X      (struct IntuiText *) &StrngText[gadcount-NUMPROPS];
  600. X    gads[gadcount].GadgetRender = NULL;
  601. X    gads[gadcount].SpecialInfo = (APTR)&SInfo[gadcount-NUMPROPS];
  602. X
  603. X    if(gadcount==NUMPROPS)
  604. X      gads[gadcount].TopEdge = 20;
  605. X    else 
  606. X      gads[gadcount].TopEdge = GADSIZE * (gadcount+2-NUMPROPS);
  607. X      gads[gadcount].NextGadget = &gads[gadcount-1];
  608. X   }   /* end for */
  609. X} /* end setupgad */
  610. X
  611. Xvoid closeout() {
  612. X
  613. X   ClearMenuStrip(w);
  614. X   CloseWindow(w);
  615. X   CloseScreen(screen);
  616. X   CloseLibrary(IntuitionBase);
  617. X   CloseLibrary(GfxBase);
  618. X
  619. X}
  620. X
  621. Xvoid displaynums(rp, funs, percent, currentfun, numoffun)
  622. X  struct   RastPort      *rp;
  623. X  float funs[][6], percent[];
  624. X  int currentfun, numoffun;
  625. X{
  626. X  short i, j, k, color;
  627. X  char str[80];
  628. X
  629. X  j = HEIGHT - (8*numoffun) - 10;
  630. X  Move(rp,0,j);
  631. X   
  632. X  for (i=0; i<=numoffun; i++) {
  633. X    if ((color = (i+2)%MAXCOLORS) < 2) 
  634. X      color = color+2;
  635. X    SetAPen(rp, color);
  636. X
  637. X    sprintf (str, "%3d ", i+1);
  638. X    Text(rp,str,strlen(str));
  639. X    for(k=0; k<6; k++) {         
  640. X      sprintf (str, "%5.2f ", funs[i][k]);
  641. X      Text(rp,str,strlen(str));
  642. X    }
  643. X    sprintf (str, "%5.2f", ((i>0) ? percent[i]-percent[i-1] : percent[i]));
  644. X    Text(rp,str,strlen(str));
  645. X    j = j+8;
  646. X    Move(rp,0,j);
  647. X   }
  648. X}
  649. X
  650. Xvoid autoadj(funs, percent, xyscale, xoff, yoff, currentfun) 
  651. X
  652. Xfloat funs[][6],percent[],*xyscale;
  653. Xint   *xoff,*yoff,*currentfun;
  654. X{
  655. Xint j;
  656. Xfloat minx = 1e20;   
  657. Xfloat miny = 1e20;  
  658. Xfloat maxx = -minx;
  659. Xfloat maxy = -minx;
  660. X
  661. Xfor (j=0;j<100;j++) 
  662. X   {graphit(funs, percent, *xyscale, *xoff, *yoff, FALSE); 
  663. X    if (x < minx) minx = x;
  664. X    if (x > maxx) maxx = x;
  665. X    if (y < miny) miny = y;
  666. X    if (y > maxy) maxy = y;
  667. X    }
  668. X
  669. X  if (maxx > minx && maxy > miny && minx > -1e20 && maxx < 1e20
  670. X    && miny > -1e20 && maxy < 1e20) {    /* don't scale if either diff = 0 */
  671. X
  672. X    if ( (maxx-minx)/WIDTH > (maxy-miny)/HEIGHT) {
  673. X      *xyscale = (SCRNSCALE*ASPECT)/ (maxx - minx);
  674. X      *xoff = (WIDTH>>1)  * (1 - (SCRNSCALE*(maxx+minx)/(maxx-minx))); 
  675. X      *yoff = (HEIGHT>>1) * (1 - (*xyscale * (maxy+miny)));
  676. X    }
  677. X    else {
  678. X      *xyscale = SCRNSCALE / (maxy - miny);
  679. X      *xoff = ((WIDTH - HEIGHT * *xyscale * (maxx-minx))/2.0) - (minx * HEIGHT * *xyscale);
  680. X      *yoff = (HEIGHT>>1) * (1 - SCRNSCALE - (2.0 * miny * *xyscale)); 
  681. X    }
  682. X
  683. X    setpots(adjwin, gads, PInfos, funs, percent, *xyscale, *xoff, *yoff,
  684. X            *currentfun, numoffun, stxt, adjopen);
  685. X
  686. X    }
  687. X}    /* end autoadj */
  688. X
  689. X
  690. Xvoid getifsfun(fname,numoffun,funs,percent,colortab,xoff,yoff,xyscale)
  691. X   char fname[MAXFNLEN];
  692. X   int *numoffun;
  693. X   float funs[][6], percent[];
  694. X   UWORD  colortab[]; 
  695. X   int *xoff,*yoff;
  696. X   float *xyscale;
  697. X{
  698. X   FILE *fp;
  699. X
  700. X   int tempcolor;
  701. X   int i, j;
  702. X  
  703. X   if ((fp = fopen(fname, "r")) == NULL) {
  704. X      printf("ifsout:  can't open %s\n", fname);
  705. X   }
  706. X   else {
  707. X      fscanf(fp, "%d %d %d %f\n", numoffun, xoff, yoff, xyscale);
  708. X      for(i=0;i <= *numoffun;i++) {
  709. X        for(j=0; j<6; j++)       
  710. X          fscanf(fp, "%f ", &funs[i][j]);
  711. X        fscanf(fp, "%f %d\n", &percent[i], &tempcolor);
  712. X        colortab[i+2] = (UWORD) tempcolor; /* assumes that i<= FUNLIMIT */
  713. X      }
  714. X      fclose(fp);
  715. X      LoadRGB4(ViewPortAddress(w), colortab, 16);
  716. X   }
  717. X}
  718. X
  719. Xvoid putifsfun(fname,numoffun,funs,percent,colortab,xoff,yoff,xyscale)
  720. X  char fname[MAXFNLEN];
  721. X  int numoffun;
  722. X  float funs[][6], percent[];
  723. X  UWORD  colortab[]; 
  724. X  int xoff,yoff;
  725. X  float xyscale;
  726. X{
  727. X  FILE *fp;
  728. X
  729. X  int i,j;
  730. X  
  731. X  if ((fp = fopen(fname, "w")) == NULL) {
  732. X    printf("ifsout:  can't open %s for write\n", fname);
  733. X   }
  734. X  else {
  735. X  fprintf(fp, "%d %d %d %f\n", numoffun, xoff, yoff, xyscale);
  736. X  for(i=0;i<=numoffun;i++) {
  737. X    for(j=0; j<6; j++)       
  738. X      fprintf(fp, "%5.2f ", funs[i][j]);
  739. X     /* assumes that FUNLIMIT <= 29 */
  740. X    fprintf(fp, " %5.2f %d\n", percent[i], colortab[i+2]);
  741. X  }
  742. X  }
  743. X  fclose(fp);
  744. X
  745. X}
  746. X
  747. X
  748. X
  749. END_OF_FILE
  750. if test 23178 -ne `wc -c <'source/ifsout.c'`; then
  751.     echo shar: \"'source/ifsout.c'\" unpacked with wrong size!
  752. fi
  753. # end of 'source/ifsout.c'
  754. fi
  755. echo shar: End of archive 3 \(of 3\).
  756. cp /dev/null ark3isdone
  757. MISSING=""
  758. for I in 1 2 3 ; do
  759.     if test ! -f ark${I}isdone ; then
  760.     MISSING="${MISSING} ${I}"
  761.     fi
  762. done
  763. if test "${MISSING}" = "" ; then
  764.     echo You have unpacked all 3 archives.
  765.     rm -f ark[1-9]isdone
  766. else
  767.     echo You still need to unpack the following archives:
  768.     echo "        " ${MISSING}
  769. fi
  770. ##  End of shell archive.
  771. exit 0
  772. -- 
  773. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  774. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  775. Post requests for sources, and general discussion to comp.sys.amiga.
  776.